package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.models.ReservationDate
import com.compass.mobile.models.Title
import getColorFromResource

/**
 * Description：
 * Date:2024/5/23 22:07
 */
class RegistrationPoolPresenter : Presenter() {
    private var finalWidth: Int? = null

    fun setFinalWidth(finalWidth: Int?) {
        this.finalWidth = finalWidth
    }

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_registration_pool, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is ReservationDate) {
            val vh = viewHolder as ViewHolder
            vh.tvDate.text = item.monthDay
            vh.tvTitle.text = item.name
            if (item.am != null && item.pm != null) {
                vh.tvIsAppointment.text="可预约"
                vh.tvIsAppointment.setTextColor(getColorFromResource(R.color.chartreuse))
            }else{
                vh.tvIsAppointment.text="未排班"
                vh.tvIsAppointment.setTextColor(getColorFromResource(R.color.main_title))
            }
        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {

    }


    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvTitle: TextView
        var tvDate: TextView
        var tvIsAppointment: TextView

        init {
            tvTitle = view.findViewById(R.id.tv_title)
            tvDate = view.findViewById(R.id.tvDate)
            tvIsAppointment = view.findViewById(R.id.tvIsAppointment)

        }
    }


}